package com.xlf.service.blog.controller.admin;

import com.xlf.common.core.annotation.Anonymous;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.service.blog.domain.Article;
import com.xlf.service.blog.domain.Comment;
import com.xlf.service.blog.domain.dto.AddCommentDTO;
import com.xlf.service.blog.domain.dto.CommentDTO;
import com.xlf.service.blog.service.ArticleService;
import com.xlf.service.blog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/blog/admin/comment")
public class AdminCommentController extends BaseController {

    @Autowired
    CommentService commentService;

    /**
     * 获取评论列表
     * @param comment
     * @return
     */
    @PreAuthorize("@ss.hasPermi('blog:admin:comment:list')")
    @GetMapping("/list")
    public AjaxResult list(Comment comment){
        startPage();
        return success(getDataTable(commentService.getList(comment)));
    }

    /**
     * 获取评论
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('blog:admin:comment:query')")
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable(value = "id")  Long id){
        return success(commentService.getById(id));
    }


    /**
     * 删除文章
     * @return
     */
    @PreAuthorize("@ss.hasPermi('blog:admin:comment:delete')")
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestBody List<Long> ids){
        commentService.removeBatchByIds(ids);
        return success("删除成功！");
    }
}
